<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller{

    public function index(){
        //头部banner
        $this->banner = getBanner();

        //所有案例类型
        $this->category = M('category')->order('id ASC')->select();

        //获取案例
        $demos      = M('demos'); // 实例化对象
        $where['status'] = 1;
        $count      = $demos->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $this->page = $Page->show();// 分页显示输出
        $this->demos = $demos->where($where)->order(array('id' => 'desc'))->limit($Page->firstRow.','.$Page->listRows)->select();

        //解决方案
        $where = array();
        $where['status'] = 1;
        $where['pid'] = 0;
        $solution_p = M('solution')->where($where)->order(array('id' => 'desc'))->select();
        if(count($solution_p) > 0){
            foreach ($solution_p as &$v){
                $v['exist_child'] = 1;
                $v['child'] = M('solution')->where(array('pid' => $v['id'], 'status'=>1))->select();
            }
        }
        $this->solution = $solution_p;
        //dump($solution_p);exit;

        //文章列表
        $this->posts = M('post')->order(array('id' => 'desc'))->limit(3)->select();

        //关于我们
        $this->about_us = M('page')->where(array('id' => 1))->find();

        $this->display();
    }
}
